package edu.pku.sei.gefcommon.descriptor.descriptors;

import org.eclipse.jface.viewers.ICellEditorValidator;

public class GeometryValidator implements ICellEditorValidator {
	private ValidType type;
	public String isValid(Object value) {
		if(type==ValidType.COLOR){
			if(((String)value).matches("([0-9]+[,][0-9]+[,][0-9]+)?"))
				return null;
		} else if(type==ValidType.POINT||type==ValidType.SIZE){
			if(((String)value).matches("[0-9]+[,][0-9]+"))
				return null;
		}
		return "Invalid gemetry value";
	}
	
	static public GeometryValidator colorValidator = new GeometryValidator(ValidType.COLOR);
	static public GeometryValidator pointValidator = new GeometryValidator(ValidType.POINT);
	static public GeometryValidator sizeValidator = new GeometryValidator(ValidType.SIZE);
	
	public GeometryValidator(ValidType type) {
		this.type = type;
	}
}
